<template>
  <div>
    <a-card class="card_box animate__animated animate__pulse" @click="cardClick">
      <div class="title_box">
        <span class="paramName">{{ props.data.paramName }}</span>
        <span class="checkTime">{{ props.data.checkTime }}</span>
        <span class="status_green"></span>
      </div>
      <div class="paramValue_box">
        <span class="value">
          <CountUp
            :startVal="0"
            :endVal="props.data.paramValue"
            :duration="2"
            :decimalPlaces="2"
            style="display: inline-block"
          ></CountUp>
        </span>
        <span class="unit">{{ props.data.paramUnit }}</span>
      </div>
      <div class="proportion_box">
        <div class="suitability">
          <span class="suitability_title title">适宜占比</span>
          <span class="suitability_value value"
            >{{ `${props.data.shiyiRatio == null ? '---' : props.data.shiyiRatio}` }}%</span
          >
        </div>
        <div class="onTheHighSide">
          <span class="onTheHighSide_title title">偏高占比</span>
          <span class="onTheHighSide_value value"
            >{{ `${props.data.piangaoRatio == null ? '---' : props.data.piangaoRatio}` }}%</span
          >
        </div>
        <div class="flat">
          <span class="flat_title title">偏低占比</span>
          <span class="flat_value value"
            >{{ `${props.data.piandiRatio == null ? '---' : props.data.piandiRatio}` }}%</span
          >
        </div>
      </div>
      <div class="footer">
        <a-button type="primary" size="small" class="footer_btn_lookHistory" @click="lookHistoryClick"
          >查看历史</a-button
        >
      </div>
    </a-card>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
export default defineComponent({
  name: 'dataCard'
})
</script>
<script lang="ts" setup>
// 引入
import CountUp from 'vue-countup-v3'
import { useRouter } from 'vue-router'
import { useEquipmentStore } from '@/store'
const equipmentStore = useEquipmentStore()

const router = useRouter()
// 查看历史的点击事件函数
const lookHistoryClick = () => {
  router.push({
    path: '/equipment/parameterDetails'
  })
}

// card的点击事件
const cardClick = () => {
  console.log(props.data)
  equipmentStore.$state.paramInfo.paramName = props.data.paramName
  equipmentStore.$state.paramInfo.paramValueUnit = props.data.paramUnit
}

// props 类型
type Props = {
  data: object
}

// 接收父组件传递的参数
const props = defineProps<Props>()

// 初始化
onMounted(() => {})
</script>

<style scoped>
.card_box {
  position: relative;
  /* padding: 20px; */
  width: 540px;
  height: 220px;
  border-radius: 4px;
  /* border-radius: 8px; */
  background: white;
  box-shadow: 3px 3px 5px #d6d5d5, -3px -3px 5px #f4f4f4;
}

.card_box:hover {
  transition: 0.3s;
  margin-top: -6px;
}

.title_box {
  padding: 10px 10px;
}
.paramName {
  font-size: 20px;
  /* font-weight: bold; */
  letter-spacing: 2px;
  font-family: '黑体';
  color: #293035;
  font-weight: bold;
}

.checkTime {
  margin-left: 20px;
  color: #8c8c8c;
  font-family: 'kaigengo-regular';
  font-size: 12px;
}

.status_green {
  width: 20px;
  height: 20px;
  display: inline-block;
  border-radius: 50%;
  background-color: rgb(33, 173, 88);
  position: absolute;
  top: 25px;
  right: 30px;
}

.paramValue_box {
  padding-left: 10px;
  line-height: 50px;
}

.paramValue_box .value {
  color: #31456a;
  font-size: 30px;
  font-family: 'kaigengo-bold';
  font-weight: bold;
}

.paramValue_box .unit {
  margin-left: 8px;
  color: #8c8c8c;
  font-size: 12px;
}
.proportion_box {
  margin-top: 8px;
  width: 400px;
  padding-left: 10px;
  display: flex;
  justify-content: space-between;
}

.proportion_box .title {
  font-size: 14px;
  font-family: 'kaigengo-regular';
  color: #8c8c8c;
}

.proportion_box .value {
  margin-left: 8px;
  font-size: 14px;
  font-family: 'kaigengo-regular';
}

.suitability .value {
  color: #19ad54;
}
.onTheHighSide .value {
  color: #f25656;
}
.flat .value {
  color: #f9b641;
}

.footer {
  margin-top: 34px;
  position: relative;
}
.footer_btn_lookHistory {
  position: absolute;
  top: 0px;
  right: 10px;
  padding: 5px 9px;
}

.card_box {
  --animate-duration: 0.8s;
}
</style>
